### Religion Paper

## Extract Cluster Composition
setwd("C:/Users/Yoru/Desktop/ECPR Religion Paper/Markdowns/Sankey")
setwd("F:/Workspace/ECPR Draft Religion/Dec 2020 Update")


## Start the Markdown and run until Euro.clust is created for cluster A (year 2000)
rm(Cluster.A)


Euro.clust$labels -> labels.a
Euro.clust$cluster -> cluster.a


## Start the Markdown and run until Euro.clust is created for cluster B (year 2014)

Euro.clust$labels -> labels.b
Euro.clust$cluster -> cluster.b




Set.A <- data.frame(labels.a, cluster.a)
Set.B <- data.frame(labels.b, cluster.b)
colnames(Set.A) <- c("labels", "cluster.a")
colnames(Set.B) <- c("labels", "cluster.b")


library(dplyr)

Set.full <- dplyr::full_join(Set.A, Set.B, by="labels")
Set.full$count <- 1


write.csv(Set.full, file="Change.2000.2014.3V.Demo.csv", row.names=FALSE)




####
library(ggplot2)
library(ggalluvial)




ggplot(data = Set.full,
       aes(axis1 = `cluster.a`, axis2 = `cluster.b`, y = count)) +
  scale_x_discrete(limits = c("Year 2000 cluster", "Year 2014 cluster"), expand = c(.1, .1)) +
  xlab("Clusters") +
  geom_alluvium(aes(fill = `cluster.b`)) +
  geom_stratum() +
  geom_text(stat = "stratum", aes(label = after_stat(stratum)), nudge_x=-.15) +
  geom_text(aes(label = as.character(labels)),
            stat = "flow", size = 3, nudge_x = .05) +
  theme(legend.position = "none") +
  ggtitle("Change in Cluster composition between 2000 and 2014",
          "Full Regulation (4-Variables)")

